﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace Common.DataAccess
{
    public abstract class AbstractEntityDataAccess<DC>
        where DC : ObjectContext, new()
    {
        [ThreadStatic]
        static DC _objectContext;
        protected static DC ObjectContext
        {
            get
            {
                if (_objectContext == null)
                {
                    _objectContext = new DC();
                }
                return _objectContext;
            }
        }

        public virtual void RejectChanges()
        {
            if (_objectContext != null)
            {
                _objectContext.Dispose();
                _objectContext = null;
            }
        }
    }
}
